﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using ZFS.Library.Helper;
using ZFS.Model;
using ZFSData;

namespace ZFS.ServerLibrary
{
    public partial class BaseService : IBaseService
    {
        public byte[] GetMenuTrees()
        {
            var MenuList = Factory.GetMenuManager().GetMenuTrees();
            byte[] bytes = ZipTools.CompressionObject(MenuList);
            return bytes;
        }

        /// <summary>
        /// 批量更新
        /// </summary>
        /// <param name="MenusBytes"></param>
        /// <returns></returns>
        public bool UpdateMenus(byte[] MenusBytes)
        {
            var MenuList = ZipTools.DecompressionObject(MenusBytes) as List<tb_Menu>;
            return Factory.GetMenuManager().UpdateMenus(MenuList);
        }

        public byte[] GetModelsByMenu(byte[] search)
        {
            var MenuSearch = ZipTools.DecompressionObject(search) as tb_Menu;
            var MenuList = Factory.GetMenuManager().GetModels(MenuSearch);
            byte[] bytes = ZipTools.CompressionObject(MenuList);
            return bytes;
        }

        public byte[] GetPagingModelsByMenu(int pageIndex, int pageSize, out int totalCount,
            byte[] search,
            bool Asc = false)
        {
            var MenuSearch = ZipTools.DecompressionObject(search) as tb_Menu;
            var MenuList = Factory.GetMenuManager().GetPagingModels(pageIndex, pageSize, out totalCount, MenuSearch, Asc);
            byte[] bytes = ZipTools.CompressionObject(MenuList);
            return bytes;
        }

        public bool DeleteEntityByMenu(byte[] entity)
        {
            var Menu = ZipTools.DecompressionObject(entity) as tb_Menu;
            return Factory.GetMenuManager().DeleteEntity(Menu);
        }

        public bool UpdateEntityByMenu(byte[] entity)
        {
            var Menu = ZipTools.DecompressionObject(entity) as tb_Menu;
            return Factory.GetMenuManager().UpdateEntity(Menu);
        }

        public byte[] AddEntityByMenu(byte[] entity)
        {
            var Menu = ZipTools.DecompressionObject(entity) as tb_Menu;
            var NewMenu = Factory.GetMenuManager().UpdateEntity(Menu);
            byte[] bytes = ZipTools.CompressionObject(NewMenu);
            return bytes;
        }

        public bool ExistEntityByMenu(byte[] entity)
        {
            var Menu = ZipTools.DecompressionObject(entity) as tb_Menu;
            return Factory.GetMenuManager().ExistEntity(Menu);
        }
    }
}
